package com.example.bms.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.Teacher;
import org.apache.ibatis.annotations.*;
import java.util.List;


/**
 * @apiNote 教师的增删改查
 * @author
 * @email 1627856348@qq.com
 * @since 1.0.0
 */
@Mapper
public interface TeacherMapper {


    /**
     * @apiNote 分页查询所有教师
     * @param page 页数
     * @author
     * @email 1627856348@qq.com
     * @return IPage<Teacher>
     * @since 1.0.0
     */
    @Select("select * from teacher")
    IPage<Teacher>  findAllPage(Page page);


    /**
     * @apiNote 查询所有教师
     * @author
     * @email 1627856348@qq.com
     * @return IPage<Teacher>
     * @since 1.0.0
     */
    @Select("select * from teacher")
    public List<Teacher> findAll();


    /**
     * @apiNote 根据教师id查询对应老师
     * @author
     * @email 1627856348@qq.com
     * @return Teacher
     * @since 1.0.0
     */
    @Select("select * from teacher where teacherId = #{teacherId}")
    public Teacher findById(Integer teacherId);


    /**
     * @apiNote 根据教师id删除对应老师
     * @author
     * @email 1627856348@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Delete("delete from teacher where teacherId = #{teacherId}")
    public int deleteById(Integer teacherId);


    /**
     * @apiNote 根据教师id修改对应老师信息
     * - teacherName 教师姓名
     * - sex 性别
     * - tel 电话号码
     * - email 邮件
     * - pwd 密码
     * - cardId 编号
     * - role 角色权限
     * - institute 学院
     * - type 职称
     * - teacherId 教师id
     * @author
     * @email 1627856348@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Update("update teacher set teacherName = #{teacherName},sex = #{sex}," +
            "tel = #{tel}, email = #{email},pwd = #{pwd},cardId = #{cardId}," +
            "role = #{role},institute = #{institute},type = #{type} where teacherId = #{teacherId}")
    public int update(Teacher teacher);


    /**
     * @apiNote 增加老师
     * - teacherName 教师姓名
     * - sex 性别
     * - tel 电话号码
     * - email 邮件
     * - pwd 密码
     * - cardId 编号
     * - role 角色权限
     * - institute 学院
     * - type 职称
     * - teacherId 教师id
     * @author
     * @email 1627856348@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Options(useGeneratedKeys = true,keyProperty = "teacherId")
    @Insert("insert into teacher(teacherName,sex,tel,email,pwd,cardId,role,type,institute) " +
            "values(#{teacherName},#{sex},#{tel},#{email},#{pwd},#{cardId},#{role},#{type},#{institute})")
    public int add(Teacher teacher);
}
